package exercise;

import java.util.Scanner;

/*
a.打印出杨辉三角形（要求打印出10行如下图）
程序分析： 它的两个边都是1，内部其它都是肩上两个数的和
           1
        1    1
      1    2    1
    1   3    3    1
  1   4    6    4   1
1   5   10   10   5   1
//6*11

1 0 0 0 0 0 0
1 1 0 0 0 0 0
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
 */
public class ex03 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入行数：");
        int n = sc.nextInt();
        ex3(n);
    }

    private static void ex3(int n) {
        int[][] arr = new int[n][n];
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i)
                    arr[i][j] = 1;//两个边都是1
                else
                    arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];//内部其它都是肩上两个数的和
            }
        }

        //输出
        for (int i = 0; i < arr.length; i++) {
            for (int k = 1; k < n - i; k++)
                System.out.print("\t");
            for (int j = 0; j <= i; j++) {
                System.out.print(arr[i][j] + "\t\t");
            }
            System.out.println();
        }
    }
}
